<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 废弃物数据管理系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background: url('/static/images/fenlei2.jpg') no-repeat center center fixed;
            background-size: cover;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .login-card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 40px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 600px;  /* 增加宽度 */
            animation: fadeIn 0.5s ease;
            position: relative;
            z-index: 1;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .login-title {
            font-size: 3.2rem;  /* 增加字体大小 */
            font-weight: 800;
            text-align: center;
            margin-bottom: 40px;  /* 增加下边距 */
            background: linear-gradient(45deg, 
                #2ecc71, /* 绿色 */
                #9b59b6, /* 紫色 */
                #e74c3c, /* 红色 */
                #f1c40f  /* 黄色 */
            );
            background-size: 300% 300%;
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            animation: gradient 8s ease infinite;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
            white-space: nowrap;  /* 防止标题换行 */
        }
        .form-control {
            border-radius: 25px;
            padding: 12px 20px;
            height: auto;
            border: 2px solid #e9ecef;
            transition: all 0.3s ease;
            font-size: 1.1rem;
        }
        .form-control:focus {
            border-color: #2ecc71;
            box-shadow: 0 0 15px rgba(46, 204, 113, 0.2);
        }
        .btn-login {
            background: linear-gradient(45deg, #2ecc71, #27ae60);
            border: none;
            border-radius: 25px;
            padding: 12px;
            font-weight: 600;
            width: 100%;
            color: white;
            transition: all 0.3s ease;
            font-size: 1.1rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-top: 20px;
        }
        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(46, 204, 113, 0.4);
        }
        .register-link {
            text-align: center;
            margin-top: 25px;
        }
        .register-link a {
            color: #2ecc71;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        .register-link a:hover {
            color: #27ae60;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            font-weight: 500;
            margin-bottom: 8px;
            color: #2c3e50;
        }
    </style>
</head>
<body>
    <div class="login-card">
        <h2 class="login-title">废弃物数据管理系统</h2>
        <form id="loginForm" method="post">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" class="form-control" id="username" name="username" 
                       placeholder="请输入用户名" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" class="form-control" id="password" name="password" 
                       placeholder="请输入密码" required>
            </div>
            <button type="submit" class="btn btn-login">登录</button>
        </form>
        <div class="register-link">
            <p>还没有账号？<a href="/register">立即注册</a></p>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            fetch('/login', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    window.location.href = '/';
                } else {
                    alert(data.error || '登录失败');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('登录失败，请重试');
            });
        });
    </script>
</body>
</html>